package cn.com.eado.uwallpaper;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.squareup.picasso.Picasso;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import cn.com.eado.uwallpaper.bean.CategoryBean;

/**
 * Created by lcy on 2015/12/23.
 */
public class GallerAdapter extends RecyclerView.Adapter<GallerAdapter.GalleryViewHolder> {

    private Context mContext;
    List<CategoryBean.ResEntity.CategoryEntity> mData;

    public GallerAdapter(Context context, List<CategoryBean.ResEntity.CategoryEntity> category) {
        mContext = context;
        mData=category;
    }

    @Override
    public GalleryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=View.inflate(mContext,R.layout.item,null);
        GalleryViewHolder viewHolder=new GalleryViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(GalleryViewHolder holder, int position) {
//        Picasso.with(mContext).load(mData.get(position).getCover()).into(holder.image);//只能是静态图片；；
        final String url="http://service.picasso.adesk.com/v1/wallpaper/category/"+mData.get(position).getId()+"/wallpaper";
//        holder.image.setTag(url);
        holder.image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(mContext,ItemActivity.class);
                intent.putExtra("url",url);
                mContext.startActivity(intent);
            }
        });
        holder.item_name.setText(mData.get(position).getName());
        Glide.with(mContext).load(mData.get(position).getCover()).into(holder.image);
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    class GalleryViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.image)
        ImageView image;
        @InjectView(R.id.item_name)
        TextView item_name;
        public GalleryViewHolder(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
            item_name.setBackgroundColor(Color.argb(50, 0, 0, 0));
        }
    }
}
